package araxy.blog.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {
    public static String getMD5(String str) {
        try {
            MessageDigest digest = MessageDigest.getInstance("md5");
            byte[] result = digest.digest(str.getBytes());
            StringBuilder buf = new StringBuilder();
            for(byte b : result) {
                int i = b & 0xff; //加盐
                String tmp = Integer.toHexString(i);
                if ( tmp.length() == 1 ) {
                    buf.append("0");
                }
                buf.append(tmp);
            }
            return  buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return "";
        }
    }
}
